<?php

namespace app\common\model\Business;

use think\Model;

/**
 * 用户领取模型
 */
class Receive extends Model
{
  // 设置当前模型对应的完整数据表名称
  protected $table = 'pre_business_receive';

  // 开启自动写入时间戳字段
  protected $autoWriteTimestamp = true;

  // 定义时间戳字段名
  protected $createTime = 'applytime';

  // 关闭自动写入update_time字段
  protected $updateTime = false;

  protected $append = [
    'status_text', // 状态
  ];

  public function getStatusTextAttr($value, $data)
  {
    $list = [
      "apply" => '申请', 'allot' => '分配', 'recovery' => '回收', 'reject' => '拒绝'
    ];

    return $list[$data['status']];
  }

  public function business()
  {
    return $this->belongsTo('app\common\model\Business\Business', 'busid', 'id', [], 'LEFT')->setEagerlyType(0);
  }
  public function admin()
  {
      return $this->belongsTo('app\admin\model\Admin', 'applyid', 'id', [], 'LEFT')->setEagerlyType(0);
  }
}
